// 用common.js必须加上Lu.addCtx("${ctxPath}");
Lu.info = function (info) {
    layer.msg(info, {icon: 6});
};
Lu.success = function (info) {
    layer.msg(info, {icon: 1});
};
Lu.error = function (info) {
    layer.msg(info, {icon: 2});
};
Lu.confirm = function (tip, ensure) {
    layer.confirm(tip, {
        skin: 'layui-layer-admin'
    }, function () {
        ensure();
    });
};
Lu.currentDate = function () {
    // 获取当前日期
    var date = new Date();

    // 获取当前月份
    var nowMonth = date.getMonth() + 1;

    // 获取当前是几号
    var strDate = date.getDate();

    // 添加分隔符“-”
    var seperator = "-";

    // 对月份进行处理，1-9月在前面添加一个“0”
    if (nowMonth >= 1 && nowMonth <= 9) {
        nowMonth = "0" + nowMonth;
    }

    // 对月份进行处理，1-9号在前面添加一个“0”
    if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
    }

    // 最后拼接字符串，得到一个格式为(yyyy-MM-dd)的日期
    return date.getFullYear() + seperator + nowMonth + seperator + strDate;
};
Lu.getUrlParam = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    } else {
        return null;
    }
};
Lu.infoDetail = function (title, info) {
    var display = "";
    if (typeof info === "string") {
        display = info;
    } else {
        if (info instanceof Array) {
            for (var x in info) {
                display = display + info[x] + "<br/>";
            }
        } else {
            display = info;
        }
    }
    top.layer.open({
        title: title,
        type: 1,
        skin: 'layui-layer-rim', //加上边框
        area: ['950px', '600px'], //宽高
        content: '<div style="padding: 20px;">' + display + '</div>'
    });
};
Lu.closeAllLoading = function () {
    layer.closeAll('loading');
};

/**
 * @param admin layuiadmin
 * @param callback 调用传入的回调函数
 */
Lu.adminOpenEnd = function(admin, callback){
    if(admin.getTempData('formOk') == true){
        Lu.success(admin.getTempData('msg'));
        if (typeof callback === "function"){
            callback();
        }
    }
};


// 以下代码是配置layui扩展模块的目录，每个页面都需要引入
layui.config({
    base: '/assets/common/module/'
}).extend({
    ax: 'ax/ax',
    // formSelects: 'formSelects/formSelects-v4',
    treeTable: 'treeTable-lay/treeTable',
    // dropdown:     'dropdown/dropdown',
    notice: 'notice/notice',
    // step: 'step-lay/step',
    // dtree: 'dtree/dtree',
    // citypicker: 'city-picker/city-picker',
    // tableSelect: 'tableSelect/tableSelect',
    ztree: 'ztree/ztree-object',
    // ztreeRight: 'ztree/ztree-object-right',
    // tip: 'constant/tip',
    selectPlus: 'select-plus/selectPlus',
    // dynamicCondition: 'dynamicCondition/dynamicCondition'
}).use(['admin'], function () {
    var $ = layui.jquery;
    var admin = layui.admin;

    // 移除loading动画
    setTimeout(function () {
        admin.removeLoading();
    }, window == top ? 600 : 100);

    //注册session超时的操作
    $.ajaxSetup({
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        complete: function (XMLHttpRequest, textStatus) {

            //通过XMLHttpRequest取得响应头，sessionstatus，
            var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
            if (sessionstatus === "timeout") {

                //如果超时就处理 ，指定要跳转的页面
                window.location = "/global/sessionError";
            }
        }
    });

});